package com.tech15.core.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.org.rapid_framework.util.ObjectUtils;

import com.tech15.core.dao.SearchDataDao;

import javacommon.base.BaseManager;
import javacommon.base.EntityDao;

@Service
@Transactional
public class SearchDataManager extends BaseManager<Object,Long>{

	private SearchDataDao searchDataDao;
	@Override
	protected EntityDao getEntityDao() {
		return searchDataDao;
	}
	
	@Transactional(readOnly=true)
	public void setSearchDataDao(SearchDataDao searchDataDao) {
		this.searchDataDao = searchDataDao;
	}

	public List<Object> searchData(String sql,String isSql,String condition,String dataType){
		boolean mark = new Boolean(isSql);
		if(mark){
			if(ObjectUtils.isNullOrEmptyString(condition)){
				return searchDataDao.searchSqlData(sql);
			}else{
				return searchDataDao.searchSqlData(sql,condition);
			}
		}else{
			if(ObjectUtils.isNullOrEmptyString(condition)){
				return searchDataDao.searchHqlData(sql);
			}else{
				Object cond = null;
				if(dataType != null && !"".equals(dataType)){
					if("Long".equals(dataType)){
						cond = new Long(condition);
					}if("Integer".equals(dataType)){
						cond = new Integer(condition);
					}else if("String".equals(dataType)){
						cond = condition;
					}
				}else{
					cond = condition;
				}
				return searchDataDao.searchHqlData(sql,cond);
			}
		}
	}
	
}
